package com.homework.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.homework.bean.CourseBean;
import com.homework.bean.HomeworkBean;
import com.homework.bean.HomeworkListBean;
import com.homework.bean.PageInfoBean;
import com.homework.bean.SimilarityBean;
import com.homework.bean.StudentHomeworkListBean;
import com.homework.bean.UserBean;
import com.homework.bean.UserSimilarityBean;
import com.homework.dao.HomeworkDao;

public class HomeworkService {

	private static HomeworkService homeworkService = null;
	private HomeworkDao homeworkDao;

	public HomeworkService() {
		this.homeworkDao = HomeworkDao.getInstance();
	}

	public static HomeworkService getInstance() {
		if (homeworkService == null) {
			homeworkService = new HomeworkService();
		}
		return homeworkService;
	}

	// 作业列表_教师
	public StudentHomeworkListBean homeworkShow_teacher(CourseBean courseBean,
			PageInfoBean pageInfoBean) throws SQLException {
		return homeworkDao.homeworkShow_teacher(courseBean, pageInfoBean);
	}

	// 作业查询_教师
	public StudentHomeworkListBean homeworkQuery_teacher(CourseBean courseBean,
			PageInfoBean pageInfoBean, UserBean userBean) throws SQLException {
		return homeworkDao.homeworkQuery_teacher(courseBean, pageInfoBean,
				userBean);
	}

	// 作业列表_学生
	public StudentHomeworkListBean homeworkShow_student(CourseBean courseBean,
			PageInfoBean pageInfoBean, UserBean userBean) throws SQLException {
		return homeworkDao.homeworkShow_student(courseBean, pageInfoBean,
				userBean);
	}

	// 作业查询_学生
	public StudentHomeworkListBean homeworkQuery_student(CourseBean courseBean,
			PageInfoBean pageInfoBean, UserBean userBean,
			HomeworkBean homeworkBean) throws SQLException {
		return homeworkDao.homeworkQuery_student(courseBean, pageInfoBean,
				userBean, homeworkBean);
	}

	// 作业列表_老师布置
	public HomeworkListBean homeworkShow_arrange(CourseBean courseBean,
			PageInfoBean pageInfoBean) throws SQLException {
		return homeworkDao.homeworkShow_arrange(courseBean, pageInfoBean);
	}

	// 作业上传
	public void homeworkUpload(UserBean userBean, CourseBean courseBean,
			HomeworkBean homeworkBean) throws SQLException {
		homeworkDao.homeworkUpload(userBean, courseBean, homeworkBean);
	}

	// 获取作业批次
	public int getBatch(UserBean userBean,CourseBean courseBean) throws SQLException {
		return homeworkDao.getBatch(userBean,courseBean);
	}
	
	// 布置作业
	public void homeworkRequirement(UserBean userBean,CourseBean courseBean,HomeworkBean homeworkBean){
		homeworkDao.homeworkRequirement(userBean,courseBean,homeworkBean);
	}

	public String getBatchOfHomeworkT(String homeworkId){
		return homeworkDao.getBatchOfHomeworkT(homeworkId);
	}
	
	// 下载作业
	public String homeworkDownload(HomeworkBean homeworkBean) throws SQLException {
		return homeworkDao.homeworkDownload(homeworkBean);
	}
	
	// 修改成绩
	public void modifyScore(HomeworkBean homeworkBean){
		homeworkDao.modifyScore(homeworkBean);
	}
	
	//通过homeworkId获取realname
	public UserBean getRealName(int homeworkId) throws SQLException{
		return homeworkDao.getRealName(homeworkId);
	}
	
	
	
	// 计算提交作业与所有已提交作业的相似度,并存入数据库中
	public boolean similarityCheck(HomeworkBean homeworkBean,
			CourseBean courseBean) {
		return homeworkDao.similarityCheck(homeworkBean, courseBean);
	}

	// 将比较相似度后的结果保存到数据库
	public boolean saveResult(SimilarityBean similarityBean) {
		return homeworkDao.saveResult(similarityBean);
	}

	//通过courseId和batch获取homeworkId和userId
	public boolean getHomeworkInfo(List<UserSimilarityBean> userSimilarity,String courseId, HomeworkBean homeworkBean) {
		return homeworkDao.getHomeworkInfo(userSimilarity,courseId,homeworkBean);
	}
	
	//动态获取batch
	public int getBatchNum(String courseId) throws NumberFormatException, SQLException {
		return homeworkDao.getBatchNum(courseId);
	}

	public String setDir(int chooseId) {
		// TODO Auto-generated method stub
		return homeworkDao.setDir(chooseId);
	}
	
	public String setDirAddress(int chooseId) {
		// TODO Auto-generated method stub
		return homeworkDao.setDirAddress(chooseId);
	}
	
	public String setDirTrack(int chooseId) {
		// TODO Auto-generated method stub
		return homeworkDao.setDirTrack(chooseId);
	}
	
	public String setDirVic(int chooseId) {
		// TODO Auto-generated method stub
		return homeworkDao.setDirVic(chooseId);
	}

	public int getChooseId(UserBean userBean, CourseBean courseBean) {
		// TODO Auto-generated method stub
		return homeworkDao.getChooseId(userBean, courseBean);
	}

	public boolean saveVirt(String lastString, HomeworkBean homeworkBean) throws IOException {
		// TODO Auto-generated method stub
		return homeworkDao.saveVirtAndEva(lastString,homeworkBean);
	}
}
